import { Text, View, ViewProps } from "@tarojs/components";
import { FC } from "react";
import { AddressInfo, DeptInfo } from "../../types/type_user";
import { utils_addressInfoToString } from "../utils/util";
import { ComButton, MyButtonProps } from "./ComButton";
import { ComSquare } from "./ComSquare";

export const ComAddressSwitchor: FC<ViewProps & MyButtonProps & {
  title?: string,
  time?: string;
  address?: AddressInfo | DeptInfo | null;
  url?: string,
  isShort?: boolean;
  addressPlaceholder?: string;
}> = ({ time, isShort = false, url, className, address, onClick, title, addressPlaceholder = "暂无地址", ...props }) => {
  const __address = utils_addressInfoToString(address, isShort, addressPlaceholder);
  const __name = (address as DeptInfo)?.deptName ?? address?.name;
  const __ccc_color = className?.includes("ccc") ? "" : "cccplh";
  return <ComButton className={`${className} ${__ccc_color}`} onClick={onClick} url={url} {...props} >
    <View className="ww dbtc ">
      <View className='dll ww'>
        <View className='dbtc ww '>
          <View className='dy h1rem ' style={{ maxHeight: "var(--rem_base)", lineHeight: "var(--rem_base)" }}>
            <Text className=' nw'>{title}</Text>
            <Text className={`nw1 wm6rem ${__name ?? ""}`}>{__name ?? "无"}</Text>
            <Text className='nw1 mr6 '>{address?.mobile}</Text>
          </View>
          <View className=' fs08 nw'>{time}</View>
        </View>
        <View className='h1rem nw1 fs08 ' style={{ maxHeight: "var(--rem_base)", lineHeight: "var(--rem_base)" }}>
          {__address ? __address : addressPlaceholder}
        </View>
      </View>
      {url && <ComSquare className='icon-chevron-right' />}
    </View>
  </ComButton>;
};